<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Test</title>
<style type="text/css">
body{ margin:0; padding:0; font-size:12px; background:#CCCCCC;}
h1{ text-align:center;}
.content{ width:960px; margin:10px auto; border:none;}
#iframe{width:100%;border:none;height:300px; margin:5px auto; background:#FFFFFF;}
</style>
</head>

<body>
<h1>Iframe 高度自适应</h1>
<div class="content">
    <iframe id="iframe" name="iframe" src="iframe.html" scrolling="no" ></iframe>
    <input id="more" type="button" value="More..（Parent 页面控制）" />白色背景部分为 iframe 页面内容。
</div>
</body>

<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="function.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#iframe").height( $(window.frames["iframe"].document).find("div[id='comments']").height()+50 );
	n = 1;
	$("#more").click(function(){
	    for(i=0;i< $(window.frames["iframe"].document).find("select[id='step']").val() ;i++){
			$.ajax({
				type: "GET",
				dataType: "json",
				url: "ajax.php?t=" + new Date().getTime(),
				data: "s="+ $(window.frames["iframe"].document).find("select[id='step']").val() +"&n=" + (n++),
				success: function(d){ 
				  $(window.frames["iframe"].document).find("div[id='comments']").append(html(d));
                  $("#iframe").height( $(window.frames["iframe"].document).find("div[id='comments']").height()+50 );
				}
			});	
		}
	})

});
</script>
</html>
